{include file="public/header"/}
<div class="layui-container">
    <div class="layui-main" style="min-height:96vh">
        <div class="layui-row" id="poster">
            
        </div>
    </div>
</div>
<script type="text/javascript">
    layui.use(['layer'], function(){
        var layer = layui.layer, $=layui.jquery;
        
        $(function(){
            createPoster();  // 创建海报
        })

        var id = "{$id}";
        function createPoster(){
            var loading = layer.msg('海报生成中..', {icon: 16,shade: 0.3,time: false});
            $.ajax({
                url:'/user/promotion_share',
                type:'post',
                data:{"id":id},
                dataType:"JSON",
                success:function(res){
                    layer.close(loading);  //返回数据关闭loading
                    if(res.code == 0){
                        console.log(res)
                        var html = `<img style="width: 100%;" src="${res.data}">
                                    <div style="position: absolute;width: 100%;text-align: center;bottom: 15px;right: 0;">
                                        <a class="layui-btn layui-bg-success" href="${res.data}" target="_blank">下载海报</a>
                                        <a class="layui-btn layui-btn-primary cancelBtn">取 消</a>
                                    </div>`;
                        $("#poster").html(html); 
                    } else{
                        layer.msg(res.msg,{icon: 2});
                    }
                },
                error:function(e){
                    layer.msg('请求失败'+e.responseText,{icon: 2});
                },
                
            });
        }

        $(document).on('click','.cancelBtn',function(){
            var index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
            parent.layer.close(index);//关闭窗口
        })
        
    });
</script>